#include <iostream>
#include <cmath>


using namespace std;

int AnnuityCalc()
{
	int choice, interval, m, n; 
	double withdrawal, rate, t, i, p, s;

	cout << "Welcome to the Annuity Calculator" << endl;
	cout << "Please select what you would like to calculate" << endl;
	cout << "1- Starting Principal" <<endl;
	cout << "2- Future Value of Annuity" <<endl;
	cout << "3- Withdrawal Amount" <<endl;
	cin >> choice;

	
	cout << "Annual Growth Rate(%): ";
	cin >> rate;
	rate = rate/100;
	cout << "Length of Annuity in Years: ";
	cin >> t;
	cout << "Interval between withdrawals- choose one of the following" << endl;
	cout << "1: Monthly \n" << "2: Quarterly \n" << "3: Semiannually \n" << "4: Yearly \n";
	cin >> interval;
	
	if (interval == 1)
	{	
		m = 12;	
	}
	else if (interval == 2)
	{ 
		m = 4;
	}
	else if (interval == 3)
	{ 
		m = 2;
	}
	else if (interval == 4)
	{ 
		m = 1;
	}
	else 
	{
		cout << "Invalid selection for interval";
		return 0;
	}	
	
	i = rate / m;
	n = t * m;

	if (choice ==1) 
	{
		cout << "Withdrawal amount: $";
		cin >> withdrawal;

		p = withdrawal * (( 1 - pow((1 + i), -n)) /i);

		cout <<"\nThe Starting Principal is: $" << p <<endl;
	}

	else if (choice ==2)
	{
		cout << "Withdrawal amount: $";
		cin >> withdrawal;

		s = withdrawal * ( (pow((1 + i), n) - 1) /i );

		cout <<"\nThe Future Value of Annuity is: $" << s <<endl;
	}

	else if (choice ==3)
	{
		cout << "Starting Principal: $";
		cin >> p;
		
		withdrawal = p / (( 1 - pow((1 + i), -n)) /i);

		cout <<"\nThe Withdrawal amount is: $" << withdrawal <<endl;
	}

	system("PAUSE");
	return 0;
}